<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>Gestionnaire de rendus</title>

<!-- CSS IMPORT -->

<style type="text/css">
@import url(./css/normalize.css);
</style>

<style type="text/css">
@import url(./css/bootstrap.min.css);
</style>

<style type="text/css">
@import url(./css/font-awesome.min.css);
</style>

<style type="text/css">
@import url(./css/font-awesome.css);
</style>

<style type="text/css">
@import url(./css/style2.css);
</style>

<link href='http://fonts.googleapis.com/css?family=Open+Sans'
	rel='stylesheet' type='text/css'>

</head>
<body onload="">

	<div class="container">

		<div class="row login">
			<div class="col-md-4 col-md-offset-1 enseirbLogo">
				<img src="./img/enseirb_matmeca.jpg" />
			</div>
			<div class="col-md-4 col-md-offset-1">
				<div class="row loginLogo">
					<!-- <img src="../img/loginBook.png" /> -->
					<i class="fa fa-book"></i>
				</div>
				<div class="row loginText">
					<p>La gestion de vos rendus en quelques clics</p>
				</div>




				<div class="row">
					<s:form action="testmydb">

						<s:textfield name="login" cssClass="form-control" id="inputLogin" label="Login"
							placeholder="Login" />

						<s:textfield name="password" type="password" label="Password"
							cssClass="form-control" id="inputPassword"
							placeholder="Mot de passe" />

						<s:submit value="Se connecter" align="center"
							cssClass="btn btn-primary btn-lg btn-block" />

					</s:form>
				</div>


				<%-- 				<div class="row">
					<form class="form-horizontal" role="form">
						<div class="form-group">
							<label for="inputLogin" class="col-sm-2 control-label">Email</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" 
									placeholder="Login">
							</div>
						</div>
						<div class="form-group">
							<label for="inputPassword" class="col-sm-2 control-label">Password</label>
							<div class="col-sm-10">
								<input type="password" class="form-control" 
									placeholder="Password">
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-10">
								<a href="javascript:testmydb()" class="btn btn-primary btn-lg btn-block">Se connecter</a>
								<div id="loginFailAlert" class="alert alert-danger" hidden><strong><i class="fa fa-warning"></i></strong> Vos identifiants ne sont pas exacts</div>
							</div>
						</div>
					</form>
				</div> --%>

			</div>
		</div>

	</div>
	<!-- /.container -->

	<!-- Javascript -->

	<script src="./js/jquery.js"></script>
	<script src="./js/bootstrap.min.js"></script>
	<script src="./js/jstorage.js"></script>

	<script>
		function testmydb() {
			$.jStorage.flush();
			var login = $("#inputLogin").val();
			var password = $("#inputPassword").val();
			console.log(login);
			if (login != null && login != '' && password != null
					&& password != '') {
				$
						.ajax({
							type : "GET",
							url : "testmydb",
							dataType : "json",
							data : {
								login : login,
								password : password
							},
							success : function(returnValue) {
								if (returnValue.user != null) {
									// On stocke en local avec jStorage les infos de l'utilisateur
									$.jStorage.set('loggedUser',
											returnValue.user);
									window.location
											.replace("http://localhost:8080/it340g2/test.action");

									$.ajax({
										type : "GET",
										url : "loginSuccess",
										success : function() {
											return;
										},
										error : function(request, error) {

										}
									});
								} else {
									$("#loginFailAlert").show();
								}

								return returnValue; // with return value excecute code
							},
							error : function(request, error) {
								alert('error');
							}
						});
			}
		}
	</script>


</body>
</html>